package com.example.springboot01.mapper;

import com.example.springboot01.model.Student;
import com.example.springboot01.model.StudentSexEnum;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;

/**
* @Auther: zrd
* @Date: 2022/3/16/03/16/16:40
* @Description: com.example.springboot01.mapper
*/
@Component
public interface StudentMapper {
    @Insert("insert into student(student_name,student_sex,grade,major)" +
            " values (#{studentName},#{studentSex},#{studentGrade},#{studentMajor})")
    void insert(Student student);

    @Select("select * from student where id=#{id}")
    @Results({
            @Result(property = "studentId",column = "id"),
            @Result(property = "studentName",column = "student_name"),
            @Result(property = "studentSex",column = "student_sex",javaType = StudentSexEnum.class),
            @Result(property = "studentGrade",column = "grade"),
            @Result(property = "studentMajor",column = "major")
    })
    Student getOne(long id);
    @Select("select * from student")
    @Results({
            @Result(property = "studentId",column = "id"),
            @Result(property = "studentName",column = "student_name"),
            @Result(property = "studentSex",column = "student_sex",javaType = StudentSexEnum.class),
            @Result(property = "studentGrade",column = "grade"),
            @Result(property = "studentMajor",column = "major")
    })
    List<Student> getAll();
    @Update("update student set student_name=#{studentName} where id=#{studentId}")
    void updateStudentName(Student student);

    @Delete("delete from student where id=#{studentId}")
    void delete(long id);

}
